function certificate_dossier() {
    var _this = this;
    var page;
    var comPIds = [];
    var departmentNames = [];
    var rootType = '';


    _this.init = function (page_person) {
        page = page_person;
        $("#recursion").attr("checked",false);
        groupTree.init({"ifShow":"false"});
        _this.addDefaultNode();
        var rootNode = getRoots()[0];
        rootType = rootNode.type;
        _this.getAllchildrenNodes(comPIds, departmentNames, rootNode, rootType);
        window.groupTree_search = _this.search;
        _this.search();
         //_this.initListTable();

        $('#click_role_type').on("click", "span", function () {
            $('#click_role_type').find("span").removeClass("active");
            $(this).addClass("active");
            _this.bind_click(this);
        });

    };

    _this.initListTable = function () {
        var companyId = $("#companyId").val();
        $("#companyIds").val("");
        $("#deptIds").val(companyId);
        _this.initTable();
    };

    _this.initTable = function () {
        var list_url = appPath + "/admin/certificate/dossier/list";
        page.init("person_form", list_url, "person_table", "person_page", 1, 10);
        page.goPage(1);

        page.list = function (dataList) {
            var len = dataList.length;
            var inner = "", item;
            // 组装数据

            for (var i = 0; i < len; i++) {
                item = dataList[i];
                inner += '<tr>';
                inner += '<td width="80">' + item['userName'] + '</td>';
                inner += '<td width="80">' + item['userAccount'] + '</td>';
                var companyName = item.companyName;
                if (companyName == '' || companyName == undefined || companyName == null) {
                    inner += "<td width='120'>" + companyName + "</td>";
                } else {
                    inner += '<td width="120">' + companyName + '</td>';
                }

                var deptName = item.departName;
                if (deptName == '' || deptName == undefined || deptName == null) {
                    inner += "<td width='80'>/</td>";
                } else {
                    inner += "<td width='80'><span>" + deptName + "</span></td>";
                }

                var certificateName = item.certificateName;
                if (certificateName == '' || certificateName == undefined || certificateName == null) {
                    inner += "<td width='120'>certificateName</td>";
                } else {
                    inner += "<td width='120'><span>" + certificateName + "</span></td>";
                }
                inner += "<td width='80'><span>" + item['certificateType'] + "</span></td>";
                inner += "<td width='90'><span>" + TimeUtil.longMsTimeConvertToDateTime(item['registerDate']) + "</span></td>";
                inner += "<td width='90'><span>" + TimeUtil.longMsTimeConvertToDateTime(item['availabeDate']) + "</span></td>";
                var certificateStatus = item.certificateStatus;
                if(certificateStatus == 1){
                    inner += "<td width='70'><span>" + "有效" + "</span></td>";
                }else if(certificateStatus == 2){

                    inner += "<td width='70' class=\"text-yellow\"><span>" + "即将失效" + "</span></td>";
                }else{

                    inner += "<td width='70'><span class=\"text-red\">" + "无效" + "</span></td>";
                }
                inner += '<td width="80">';
                inner += '<a href="javascript:certificate_dossier.userCertificateInfo(\''+item['id']+'\')" class="a a-info" >详情</a>'
                inner += '</td>';
                inner += '</tr>';
            }
            return inner;
        }
    };

    function getAllParentNodes(deptId) {
        var contactName = '';
        var treeObj = $.fn.zTree.getZTreeObj(tree_options.id);
        var treeNode = treeObj.getNodeByParam("id", deptId, null);
        if (treeNode == null) {
            return "";
        } else if (treeNode.type == "1") {
            return "";
        } else {
            contactName = contactName == '' ? treeNode.name : treeNode.name + '/' + contactName;
            if (treeNode.getParentNode()) {
                var vl = getAllParentNodes(treeNode.getParentNode().id);
                if (vl != '') {
                    contactName = contactName == '' ? vl : vl + '/' + contactName;
                }
            }
        }
        return contactName;
    }

    //搜索高亮
    function getFontCss(treeId, treeNode) {
        return (!!treeNode.highlight) ? {'color': "#A60000", 'font-weight': "bold"} : {
            'color': "#333",
            'font-weight': "normal"
        };
    }

    // 获取根节点集合
    function getRoots() {
        var treeObj = $.fn.zTree.getZTreeObj(tree_options.id);
        return treeObj.getNodesByFilter(function (node) {
            return node.level == 0;
        });
    }


    _this.getRole = function () {
        var treeObj = $.fn.zTree.getZTreeObj(tree_options.id);
        var rootNode = this.getRoots()[0];
        treeObj.selectNode(rootNode);
        treeObj.setting.callback.onClick(null, tree_options.id, rootNode);
    };


    /**
     * 得到勾选的单选框
     * @returns {string}
     *
     */
    _this.getCheckedRows_ids = function () {
        // var length = $("#person_table").find("input[type=checkbox]:checked").length;
        // alert(length);
        var userIds = "";
        $("#person_table").find("input[type=checkbox]:checked").each(function () {
            userIds += userIds == '' ? $(this).val() : "," + $(this).val();
        });
        return userIds;
    };



    _this.checkboxChange = function () {
        if ($("#recursion").prop("checked")) {
            groupTree.init({"ifShow":"true"});
        }else{
            groupTree.init({"ifShow":"false"});
        }
        _this.addDefaultNode();
        _this.search();
    };

    _this.search = function (selectedNode) {
        var selectedNodes = $.fn.zTree.getZTreeObj("group_tree").getSelectedNodes();
        var treeNode = selectedNodes[0];
        // 获取左侧选中节点
        // 获取左侧选中节点
        var companyId = (treeNode.companyId) ? treeNode.companyId : "";
        var departmentId = (treeNode.departmentId) ? treeNode.departmentId : "";
        var departmentName = (treeNode.name) ? treeNode.name : "";
        var type = treeNode.type;
        var id = treeNode.id.toString();
        $("#departmentId").attr("value", departmentId);
        $("#departmentName").attr("value", departmentName);
        var array = [];
        _this.getAllchildrenNodes(array, null, treeNode, type);

        //根节点/单位节点
        if("1" == type || "2" == type){
            $("#companyIds").val(companyId);
            $("#companyId").val(companyId);
            $("#deptIds").val("");
        }else{
            $("#companyIds").val("");
            $("#companyId").val("");
            $("#deptIds").val(array);
        }
        _this.initTable();
    };

    _this.addDefaultNode = function () {
        var rootNode = getRoots()[0];
        if (rootNode.type != '3') {
            var treeNode = new Object();
            treeNode.id = '-2';
            treeNode.pid = rootNode.id;
            treeNode.name = '调动人员';
            treeNode.companyId = rootNode.id;
            treeNode.departmentId = "-2";
            treeNode.type = '4';
            treeNode.icon = appPath + "/static/global/js/zTree/css/zTreeStyle/img/department.png";
            groupTree.zTree.addNodes(rootNode, treeNode, false);
        }
        var treeNode1 = new Object();
        treeNode1.id = '-1';
        treeNode1.pid = rootNode.id;
        treeNode1.name = '离职人员';
        treeNode1.companyId = rootNode.id;
        treeNode1.departmentId = "-1";
        treeNode1.type = '4';
        treeNode1.icon = appPath + "/static/global/js/zTree/css/zTreeStyle/img/department.png";
        groupTree.zTree.addNodes(rootNode, treeNode1, false);
    };

//获取某一节点下的所有子节点
    _this.getAllchildrenNodes = function (array, deptNames, treeNode, type) {
        array.push(treeNode.id);
        if (null != deptNames) {
            deptNames.push(treeNode.name);
        }
        if (treeNode.isParent) {
            var childrenNodes = treeNode.children;
            if (childrenNodes) {
                var len = childrenNodes.length;
                if (type == '4') {
                    for (var i = 0; i < len; i++) {
                        _this.getAllchildrenNodes(array, deptNames, childrenNodes[i], type);
                    }
                } else if (type == '3') {
                    for (var m = 0; m < len; m++) {
                        if (childrenNodes[m].type == '4') {
                            continue;
                        }
                        _this.getAllchildrenNodes(array, deptNames, childrenNodes[m], type);
                    }
                } else {
                    for (var j = 0; j < len; j++) {
                        if (childrenNodes[j].type == '3' || childrenNodes[j].type == '4') {
                            continue;
                        }
                        _this.getAllchildrenNodes(array, deptNames, childrenNodes[j], type);
                    }
                }
            }
        }
        return array;
    };

    _this.searchAll = function () {
        $("#person_form").find("input[name=user_name]").val("");
        $("#person_form").find("input[name=role_name]").val("");
        _this.initTable();
    };

    _this.bind_click = function (t) {
        var value = $(t).attr("data-value");
        $("#person_form").find("input[name=role_id]").val(value);
        _this.initTable();
    };



    _this.ajax = function (url, param, type) {
        var result;
        $.ajax({
            url: url,
            async: false,
            type: 'post',
            data: param,
            success: function (data) {
                result = data;
            }
        });
        return result;
    };


    // 持证新增
    _this.toCer =function (id){
        layer.open({
            type: 2,
            title: '证书详情',
            area: ['700px', '700px'],		//弹出层大小
            scrollbar: false,				//false隐藏滑动块
            content: [appPath + '/admin/certificate/certificateInfo?id=' +id, 'yes']
        });
    };

    // 详情
    _this.userCertificateInfo = function (varId) {
        //window.open(appPath + "/admin/certificate/userCertificateInfo?varId=" + varId);
        window.location.href = appPath + "/admin/certificate/userCertificateInfo?varId=" + varId;
    }
}

var certificate_dossier = new certificate_dossier();


